//
//  ViewController.m
//  24-HomeWork
//
//  Created by 李昊林 on 16/8/16.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "AFHTTPSessionManager.h"
#import "NSString+LHLMD5.h"
@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *textOfEncrypt;
@property (weak, nonatomic) IBOutlet UITextField *textOfDecrypt;




@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
}

- (IBAction)buttonOfEncrypt:(id)sender {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSString *urlString = @"http://tool.zzblo.com/api/md5/encrypt";
    
    NSString *parmeters = [@"text=" stringByAppendingString:self.textOfEncrypt.text];
    
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        
        return parmeters;
    }];
    [manager POST:urlString parameters:parmeters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"%@", responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
- (IBAction)buttonOfDecrypt:(id)sender {
    
    
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSString *urlString = @"http://tool.zzblo.com/api/md5/decrypt";
    
    NSString *parmeters = [@"secret=" stringByAppendingString:self.textOfDecrypt.text];
    
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        
        return parmeters;
    }];
    [manager POST:urlString parameters:parmeters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"%@", responseObject);
        self.textOfEncrypt.text = [responseObject objectForKey:@"text"];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
